/**
 * 
 */
package wong.board.client.widgets;

import java.util.List;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.IsWidget;

/**
 * @author wong
 * 
 */
public class Table extends Container {

	/**
	 * 
	 */
	public Table() {
		this.setStyleName(widgetsCss.table());
	}

	public void addRowHead(IsWidget... widgets) {
		if (widgets != null) {
			FlowPanel row = new FlowPanel();
			row.setStyleName(widgetsCss.tableRow());
			for (IsWidget widget : widgets) {
				widget.asWidget().addStyleName(widgetsCss.tableHeader());
				row.add(widget);
			}
			getContainer().add(row);
		}
	}

	public IsWidget addRowData(List<IsWidget> widgets) {
		return addRowData(widgets.toArray(new IsWidget[widgets.size()]));
	}

	public IsWidget addRowData(IsWidget... widgets) {
		if (widgets != null) {
			FlowPanel row = new FlowPanel();
			row.setStyleName(widgetsCss.tableRow());
			for (IsWidget widget : widgets) {
				widget.asWidget().addStyleName(widgetsCss.tableData());
				row.add(widget);
			}
			getContainer().add(row);
			return row;
		}
		return null;
	}

	public void clear() {
		getContainer().clear();
	}

}
